home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / stdlib1.exe / lha / TEST.ASM < prev    next >
Assembly Source File  |  1991-03-13  |  31KB  |  1,813 lines

  1.         include    stdlib.a
  2. ;****************************************************************************
  3. ;
  4. ; T  E  S  T       S  U  I  T  E      F  O  R   
  5. ;
  6. ;
  7. ; R  A  N  D  Y      H  Y  D  E ' S     S  T  A  N  D  A  R  D
  8. ;
  9. ; L  I  B  R  A  R  Y     F  O  R     A  S  S  E  M  B  L  Y   
  10. ;
  11. ; L  A  N  G  U  A  G  E     P  R  O  G  R  A  M  M  E  R  S
  12. ;
  13. ;****************************************************************************
  14. ;
  15. ;
  16. ; Global variables go here:
  17. ;
  18. dseg        segment    para public 'data'
  19. i        dw    -4321
  20. pi        dd    i
  21. u        dw    2345
  22. pu        dd    u
  23. l        dd    -1234567890
  24. pl        dd    l
  25. ul        dd    987654321
  26. pul        dd    ul
  27. ;
  28. ps        dd    s
  29. s        db    "Printf string",0
  30. TestString0    db    "This string gets printed by puts!",cr,lf,0
  31. TestString1    db    "This string gets used by the STRxxx Routines",cr,lf,0
  32. TestString2    db    "gets",0
  33. TestString3    db    "Hello there",0
  34. TestString4    db    "THIS STRING GETS USED BY THE STRXXX ROUTINES",cr,lf,0
  35. TestString5    db    "all lower case",cr,lf,0
  36. TestString6    db    "Clear out this string",0
  37. StringSet1    db    "Tabcdefghijklmnopqrst ",0
  38. StringSet2    db    "uvwxyz!",0
  39. InsStrSrc    db    "Insert This",0
  40. InsStrDest    db    "--><--",0
  41. RevStr1        db    "012345",0
  42. RevStr2        db    "0123456",0
  43. RevStr3        db    "1",0
  44. RevStr4        db    0
  45. buffer        db    256 dup (?)
  46. buffer2        db    256 dup (?)
  47. sfstr1        db    "1 -1 1 65000 100000 -100000 1 4000000000 0abc x",0
  48. sfstr2        db    "1, 2",0
  49. hex1        db    "12ab",0
  50. int1        db    "-12345",0
  51. int2        db    "65000",0
  52. lint1        db    "-2000000000",0
  53. lint2        db    "4000000000",0
  54. i1        dw    ?
  55. i2        dw    ?
  56. u1        dw    ?
  57. u2        dw    ?
  58. l1        dd    ?
  59. l2        dd    ?
  60. ul1        dd    ?
  61. ul2        dd    ?
  62. h1        dw    ?
  63. c1        db    ?
  64. c2        db    '!'
  65. MemAvail    dw    ?
  66. ;
  67. ; Allocate some character sets down here
  68. ;
  69.         set    charset, cs2, cs3, cs4
  70. ;
  71. dseg        ends
  72. ;
  73. ;
  74. ;
  75. ;
  76. cseg        segment    para public 'code'
  77.         assume    cs:cseg, ds:dseg
  78. ;
  79. ;
  80. lesi        macro    adrs
  81.         mov     di, seg adrs
  82.         mov    es, di
  83.         lea    di, adrs
  84.         endm
  85. ;
  86. ldxi        macro    adrs
  87.         mov    dx, seg adrs
  88.         lea    si, adrs
  89.         endm
  90. ;
  91. ; Variables that wind up being used by the standard library routines.
  92. ; The MemInit routine uses "PSP" and "zzzzzzseg" labels.  They must be
  93. ; present if you intend to use getenv, MemInit, malloc, and free.
  94. ;
  95. ;
  96.         public    PSP
  97. PSP        dw    ?
  98. ;
  99. cr        equ    13
  100. lf        equ    10
  101. ;
  102. ;
  103. ; Main is the main program.  Program execution always begins here.
  104. ;
  105. Main        proc
  106.         mov    cs:PSP, es        ;Save pgm seg prefix
  107.         mov    ax, seg dseg        ;Set up the segment registers
  108.         mov    ds, ax
  109.         mov    es, ax
  110.         mov    dx, 0            ;Allocate all available RAM.
  111.         MemInit
  112.         mov    MemAvail, cx
  113.         printf
  114.         db    "There are %x paragraphs of memory available."
  115.         db    cr,lf,lf,0
  116.         dd    MemAvail
  117. ;
  118. ;
  119. ;
  120. ;
  121. ;***************************************************************************
  122. ;
  123. ; Test the StrRev and StrRev2 routines here.
  124. ;
  125.         print
  126.         db    "Testing StrRev:",cr,lf,0
  127.         lesi    RevStr1
  128.         strrev
  129.         puts
  130.         putcr
  131.         strrev
  132.         puts
  133.         putcr
  134.                 putcr
  135. ;
  136.         lesi    RevStr2
  137.         strrev
  138.         puts
  139.         putcr
  140.         strrev
  141.         puts
  142.         putcr
  143.                 putcr
  144. ;
  145.         lesi    RevStr3
  146.         strrev
  147.         puts
  148.         putcr
  149.         strrev
  150.         puts
  151.         putcr
  152.                 putcr
  153. ;
  154.         lesi    RevStr4
  155.         strrev
  156.         puts
  157.         putcr
  158.         strrev
  159.         puts
  160.         putcr
  161. ;
  162. ;
  163.         print
  164.         db    "Testing StrRev2:",cr,lf,0
  165.         lesi    RevStr1
  166.         strrev2
  167.         puts
  168.         putcr
  169.         free
  170. ;
  171.         lesi    RevStr2
  172.         strrev2
  173.         puts
  174.         putcr
  175.         free
  176. ;
  177.         lesi    RevStr3
  178.         strrev2
  179.         puts
  180.         putcr
  181.         free
  182. ;
  183.         lesi    RevStr4
  184.         strrev2
  185.         puts
  186.         putcr
  187.         free
  188.         putcr
  189. ;
  190. ;
  191. ;***************************************************************************
  192. ;
  193. ; Test the STRINS and STRDEL routines here.
  194. ;
  195.         print
  196.         db    "Testing StrDel:",cr,lf,0
  197.         ldxi    buffer
  198.         lesi    InsStrDest
  199.         strcpy
  200.         mov    ax, 2
  201.         mov    cx, ax
  202.         strdel
  203.         puts
  204.         putcr
  205. ;
  206.         ldxi    buffer
  207.         lesi    InsStrDest
  208.         strcpy
  209.         mov    ax, 20
  210.         mov    cx, 2
  211.         strdel
  212.         puts
  213.         putcr
  214. ;
  215.         print
  216.         db    "Testing StrDel2:",cr,lf,0
  217.         lesi    InsStrDest
  218.         mov    ax, 2
  219.         mov    cx, ax
  220.         strdel2
  221.         puts
  222.         putcr
  223.         free
  224. ;
  225.         lesi    InsStrDest
  226.         mov    ax, 20
  227.         mov    cx, 2
  228.         strdel2
  229.         puts
  230.         putcr
  231.         free
  232. ;
  233.         print
  234.         db    "Testing StrInsl:",cr,lf,0
  235.         ldxi    buffer
  236.         lesi    InsStrDest
  237.         strcpy
  238. ;
  239.         mov    cx, 3
  240.         strinsl
  241.         db    "Hi there",0
  242.         puts
  243.         putcr
  244. ;
  245.         print
  246.         db    "Testing StrIns2l:",cr,lf,0
  247.         lesi    InsStrDest
  248.         mov    cx, 3
  249.         strins2l
  250.         db    "Ho ho ho!",0
  251.         puts
  252.         putcr
  253.         free
  254. ;
  255.         lesi    InsStrDest
  256.         mov    cx, 100
  257.         strins2l
  258.         db    "and a bottle of rum!",cr,lf,0
  259.         puts
  260.         putcr
  261.         free
  262. ;
  263.         print
  264.         db    "Testing STRINS2:",cr,lf,0
  265.         lesi    InsStrDest
  266.         ldxi    InsStrSrc
  267.         mov    cx, 3
  268.         strins2
  269.         jnc    GoodStrins2
  270.         print
  271.         db    "Could not allocate memory for StrIns2",cr,lf,0
  272.         jmp    short BadStrins2
  273. ;
  274. GoodStrins2:    puts
  275.         putcr
  276.         free
  277. ;
  278. BadStrIns2:    lesi    InsStrDest
  279.         ldxi    InsStrSrc
  280.         mov    cx, 100
  281.         strins2
  282.         jnc    GoodSI2
  283.         print
  284.         db    "Strins2:memory allocation error",cr,lf,0
  285.         jmp    short BSI2
  286. ;
  287. GoodSI2:    puts
  288.         putcr
  289.         free
  290. ;
  291. BSI2:        print
  292.         db    "Testing STRINS:",cr,lf,0
  293.         lesi    InsStrDest
  294.         ldxi    InsStrSrc
  295.         mov    cx, 3
  296.         strins
  297.         puts
  298.         putcr
  299.         lesi    InsStrDest
  300.         ldxi    InsStrSrc
  301.         mov    cx, 100
  302.         strins
  303.         puts
  304.         putcr
  305. ;
  306. ;
  307. ;***************************************************************************
  308. ;
  309. ; Test the character set routines down here:
  310. ;
  311.         print  
  312.         db    "Testing RangeSet:",cr,lf,0
  313.         mov    al, 'A'
  314.         mov    ah, 'F'
  315.         lesi    CharSet
  316.         rangeset
  317.         print
  318.         db    "Chars in set: ",0
  319.         call    PrintSet
  320. ;
  321.         print
  322.         db    cr,lf,lf,"Testing addstr, addstrl:",cr,lf,0
  323.         lesi    cs2
  324.         ldxi    StringSet2
  325.         addstr
  326.         addstrl
  327.         db    "aAbBcCdDeEfF",0
  328.         print
  329.         db    "Chars in set: ",0
  330.         call    PrintSet
  331. ;
  332.         print
  333.         db    cr,lf,lf,"Testing rmvstr, rmvstrl:",cr,lf,0
  334.         lesi    cs2
  335.         ldxi    StringSet2
  336.         rmvstr
  337.         rmvstrl
  338.         db    "ABCDEF",0
  339.         print
  340.         db    "Chars in set: ",0
  341.         call    PrintSet
  342. ;
  343.         print
  344.         db    cr,lf,lf,"Testing addchar/rmvchar:",cr,lf,0
  345.         lesi    cs2
  346.         mov    al, 'A'
  347.         addchar
  348.         mov    al, 'a'
  349.         rmvchar
  350.         print
  351.         db    "Chars in set: ",0
  352.         call    PrintSet
  353. ;
  354.         print
  355.         db    cr,lf,lf,"Testing emptyset:",cr,lf,0
  356.         emptyset
  357.         print
  358.         db    "Chars in set: ",0
  359.         call    PrintSet
  360. ;
  361.         print
  362.         db    cr,lf,lf,"Testing member:",cr,lf,0
  363.         addstrl
  364.         db    "ABCDEF",0
  365.         mov    al, 'A'
  366.         member
  367.         jne    NotInSet1
  368.         print
  369.         db    "A was not in the set",0
  370.         jmp    short NIS1
  371. ;
  372. NotInSet1:    print
  373.         db    "A is in the set",0
  374. NIS1:        putcr
  375.         mov    al, "G"
  376.         member
  377.         jne    NotInSet2
  378.         print
  379.         db    "G is not in the set",0
  380.         jmp    short NIS2
  381. ;
  382. NotInSet2:    print
  383.         db    "G is in the set",0
  384. NIS2:        putcr
  385. ;
  386.         print
  387.         db    cr,lf,lf,"Testing copyset:",cr,lf,0
  388.         mov    dx, es
  389.         mov    si, di
  390.         lesi    cs3
  391.         copyset
  392.         print
  393.         db    "Value in cs3: ",0
  394.         call    Printset
  395. ;
  396.         print    
  397.         db    cr,lf,lf,"Testing unionset:",cr,lf,0
  398.         addstrl
  399.         db    "ABCDEFuvwxyz",0
  400.         ldxi    cs2
  401.         setunion
  402.         print
  403.         db    "Chars in set: ",0
  404.         call    Printset
  405. ;
  406.         print
  407.         db    cr,lf,lf,"Testing set difference",cr,lf,0
  408.         ldxi    cs2
  409.         setdifference
  410.         print
  411.         db    "Chars in set: ",0
  412.         call    PrintSet
  413. ;
  414. ;
  415. ;
  416. ;***************************************************************************
  417. ;
  418. ; Test the STRxxx routines here.
  419. ;
  420. ;
  421. ;*Strspan
  422. ;
  423.         print
  424.         db    cr,lf,lf,"Testing strspan:",cr,lf,0
  425. ;
  426.         lesi    TestString1
  427.         ldxi    StringSet1
  428.         strspan
  429.         mov    i1, cx
  430.         printf
  431.         db    "TestString1 contains a character not found in "
  432.         db    "StringSet1 at position %d\n\n",0
  433.         dd    i1
  434. ;
  435. ;
  436. ;*Strspanl
  437. ;
  438.         print
  439.         db    "Testing strspanl:",cr,lf,0
  440. ;
  441.         lesi    TestString1
  442.         strspanl
  443.         db    "Tabcdefghijklmnopqrst ",0
  444.         mov    i1, cx
  445.         printf
  446.         db    "TestString1 contains a character not found in "
  447.         db    "the set at position %d\n\n",0
  448.         dd    i1
  449. ;
  450. ;
  451. ;*Strcspan
  452. ;
  453.         print
  454.         db    "Testing strcspan:",cr,lf,0
  455. ;
  456.         lesi    TestString1
  457.         ldxi    StringSet2
  458.         strcspan
  459.         mov    i1, cx
  460.         printf
  461.         db    "TestString1 contains a character found in "
  462.         db    "StringSet2 at position %d\n\n",0
  463.         dd    i1
  464. ;
  465. ;
  466. ;*Strcspanl
  467. ;
  468.         print
  469.         db    "Testing strcspanl:",cr,lf,0
  470. ;
  471.         lesi    TestString1
  472.         strcspanl
  473.         db    "uvwxyz!",0
  474.         mov    i1, cx
  475.         printf
  476.         db    "TestString1 contains a character not found in "
  477.         db    "the set at position %d\n\n",0
  478.         dd    i1
  479. ;
  480. ;
  481. ;*Strset, Strset2
  482. ;
  483.         print
  484.         db    "Testing Strset",cr,lf,0
  485. ;
  486.         lesi    TestString6
  487.         mov    al, '*'
  488.         strset
  489.         puts
  490. ;
  491. ;
  492.         print
  493.         db    cr,lf,lf,"Testing StrSet2:",cr,lf,0
  494.         mov    cx, 32
  495.         mov    al, '#'
  496.         strset2
  497.         puts
  498.         free
  499.         putcr
  500.         put